
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/concrete.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:08 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Concrete &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../_static/sympy-notailtext-favicon.ico"/>
    <link href="concrete.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Core" href="core.html" />
    <link rel="prev" title="Polycyclic Groups" href="combinatorics/pc_groups.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="core.html" title="Core"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="combinatorics/pc_groups.html" title="Polycyclic Groups"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Concrete</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="concrete">
<h1>Concrete<a class="headerlink" href="#concrete" title="Permalink to this headline">¶</a></h1>
<section id="hypergeometric-terms">
<h2>Hypergeometric terms<a class="headerlink" href="#hypergeometric-terms" title="Permalink to this headline">¶</a></h2>
<p>The center stage, in recurrence solving and summations, play hypergeometric
terms. Formally these are sequences annihilated by first order linear
recurrence operators. In simple words if we are given term <span class="math notranslate nohighlight">\(a(n)\)</span> then it is
hypergeometric if its consecutive term ratio is a rational function in <span class="math notranslate nohighlight">\(n\)</span>.</p>
<p>To check if a sequence is of this type you can use the <code class="docutils literal notranslate"><span class="pre">is_hypergeometric</span></code>
method which is available in Basic class. Here is simple example involving a
polynomial:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span><span class="p">,</span> <span class="n">k</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;n,k&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">n</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Of course polynomials are hypergeometric but are there any more complicated
sequences of this type? Here are some trivial examples:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gamma</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>We see that all species used in summations and other parts of concrete
mathematics are hypergeometric. Note also that binomial coefficients and both
rising and falling factorials are hypergeometric in both their arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>To say more, all previously shown examples are valid for integer linear
arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">binomial</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rf</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ff</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gamma</span><span class="p">(</span><span class="mi">5</span><span class="o">*</span><span class="n">n</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">7</span><span class="p">))</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>However nonlinear arguments make those sequences fail to be hypergeometric:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="p">(</span><span class="n">n</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">is_hypergeometric</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
<p>If not only the knowledge of being hypergeometric or not is needed, you can use
<code class="docutils literal notranslate"><span class="pre">hypersimp()</span></code> function. It will try to simplify combinatorial expression and
if the term given is hypergeometric it will return a quotient of polynomials of
minimal degree. Otherwise is will return <span class="math notranslate nohighlight">\(None\)</span> to say that sequence is not
hypergeometric:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">hypersimp</span><span class="p">(</span><span class="n">factorial</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span><span class="p">),</span> <span class="n">n</span><span class="p">)</span>
<span class="go">2*(n + 1)*(2*n + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hypersimp</span><span class="p">(</span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="n">n</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="concrete-class-reference">
<h2>Concrete Class Reference<a class="headerlink" href="#concrete-class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.concrete.summations.Sum">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.concrete.summations.</span></span><span class="sig-name descname"><span class="pre">Sum</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L31-L857"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.Sum" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents unevaluated summation.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">Sum</span></code> represents a finite or infinite series, with the first argument
being the general form of terms in the series, and the second argument
being <code class="docutils literal notranslate"><span class="pre">(dummy_variable,</span> <span class="pre">start,</span> <span class="pre">end)</span></code>, with <code class="docutils literal notranslate"><span class="pre">dummy_variable</span></code> taking
all integer values from <code class="docutils literal notranslate"><span class="pre">start</span></code> through <code class="docutils literal notranslate"><span class="pre">end</span></code>. In accordance with
long-standing mathematical convention, the end term is included in the
summation.</p>
<p class="rubric">Finite Sums</p>
<p>For finite sums (and sums with symbolic limits assumed to be finite) we
follow the summation convention described by Karr [1], especially
definition 3 of section 1.4. The sum:</p>
<div class="math notranslate nohighlight">
\[\sum_{m \leq i &lt; n} f(i)\]</div>
<p>has <em>the obvious meaning</em> for <span class="math notranslate nohighlight">\(m &lt; n\)</span>, namely:</p>
<div class="math notranslate nohighlight">
\[\sum_{m \leq i &lt; n} f(i) = f(m) + f(m+1) + \ldots + f(n-2) + f(n-1)\]</div>
<p>with the upper limit value <span class="math notranslate nohighlight">\(f(n)\)</span> excluded. The sum over an empty set is
zero if and only if <span class="math notranslate nohighlight">\(m = n\)</span>:</p>
<div class="math notranslate nohighlight">
\[\sum_{m \leq i &lt; n} f(i) = 0  \quad \mathrm{for} \quad  m = n\]</div>
<p>Finally, for all other sums over empty sets we assume the following
definition:</p>
<div class="math notranslate nohighlight">
\[\sum_{m \leq i &lt; n} f(i) = - \sum_{n \leq i &lt; m} f(i)  \quad \mathrm{for} \quad  m &gt; n\]</div>
<p>It is important to note that Karr defines all sums with the upper
limit being exclusive. This is in contrast to the usual mathematical notation,
but does not affect the summation convention. Indeed we have:</p>
<div class="math notranslate nohighlight">
\[\sum_{m \leq i &lt; n} f(i) = \sum_{i = m}^{n - 1} f(i)\]</div>
<p>where the difference in notation is intentional to emphasize the meaning,
with limits typeset on the top being inclusive.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">i</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">Sum(k, (k, 1, m))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">m**2/2 + m/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">Sum(k**2, (k, 1, m))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">m**3/3 + m**2/2 + m/6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">Sum(x**k, (k, 0, oo))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">Piecewise((1/(1 - x), Abs(x) &lt; 1), (Sum(x**k, (k, 0, oo)), True))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">k</span><span class="o">/</span><span class="n">factorial</span><span class="p">(</span><span class="n">k</span><span class="p">),</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">exp(x)</span>
</pre></div>
</div>
<p>Here are examples to do summation with symbolic indices.  You
can use either Function of IndexedBase classes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">f(0) + f(1) + f(2) + f(3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">Sum(f(n), (n, 0, oo))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">f[0]**2 + f[1]**2 + f[2]**2 + f[3]**2</span>
</pre></div>
</div>
<p>An example showing that the symbolic result of a summation is still
valid for seemingly nonsensical values of the limits. Then the Karr
convention allows us to give a perfectly valid interpretation to
those sums by interchanging the limits according to the above rules:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span>
<span class="go">n**2/2 + n/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="o">-</span><span class="mi">4</span><span class="p">)</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">4</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="o">-</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">6</span>
</pre></div>
</div>
<p>An explicit example of the Karr summation convention:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">i</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="o">+</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span>
<span class="go">m**2*n + m*n**2 - m*n + n**3/3 - n**2/2 + n/6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S2</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">i</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">m</span><span class="o">+</span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S2</span>
<span class="go">-m**2*n - m*n**2 + m*n - n**3/3 + n**2/2 - n/6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">+</span> <span class="n">S2</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S3</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">m</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S3</span>
<span class="go">0</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.summations.summation" title="sympy.concrete.summations.summation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">summation</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product" title="sympy.concrete.products.Product"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Product</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.product" title="sympy.concrete.products.product"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.product</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r80"><span class="brackets"><a class="fn-backref" href="#id1">R80</a></span></dt>
<dd><p>Michael Karr, “Summation in Finite Terms”, Journal of the ACM,
Volume 28 Issue 2, April 1981, Pages 305-350
<a class="reference external" href="http://dl.acm.org/citation.cfm?doid=322248.322255">http://dl.acm.org/citation.cfm?doid=322248.322255</a></p>
</dd>
<dt class="label" id="r81"><span class="brackets"><a class="fn-backref" href="#id2">R81</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Summation#Capital-sigma_notation">https://en.wikipedia.org/wiki/Summation#Capital-sigma_notation</a></p>
</dd>
<dt class="label" id="r82"><span class="brackets"><a class="fn-backref" href="#id3">R82</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Empty_sum">https://en.wikipedia.org/wiki/Empty_sum</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.summations.Sum.euler_maclaurin">
<span class="sig-name descname"><span class="pre">euler_maclaurin</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eval_integral</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L675-L777"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.Sum.euler_maclaurin" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an Euler-Maclaurin approximation of self, where m is the
number of leading terms to sum directly and n is the number of
terms in the tail.</p>
<p>With m = n = 0, this is simply the corresponding integral
plus a first-order endpoint correction.</p>
<p>Returns (s, e) where s is the Euler-Maclaurin approximation
and e is the estimated error (taken to be the magnitude of
the first omitted term in the tail):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">k</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span><span class="o">.</span><span class="n">evalf</span><span class="p">()</span>
<span class="go">1.28333333333333</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="p">,</span> <span class="n">e</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">euler_maclaurin</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span>
<span class="go">-log(2) + 7/20 + log(5)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sstr</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">sstr</span><span class="p">((</span><span class="n">s</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="n">e</span><span class="o">.</span><span class="n">evalf</span><span class="p">()),</span> <span class="n">full_prec</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">(1.26629073187415, 0.0175000000000000)</span>
</pre></div>
</div>
<p>The endpoints may be symbolic:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="p">,</span> <span class="n">e</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span><span class="o">.</span><span class="n">euler_maclaurin</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span>
<span class="go">-log(a) + log(b) + 1/(2*b) + 1/(2*a)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span>
<span class="go">Abs(1/(12*b**2) - 1/(12*a**2))</span>
</pre></div>
</div>
<p>If the function is a polynomial of degree at most 2n+1, the
Euler-Maclaurin formula becomes exact (and e = 0 is returned):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span><span class="o">.</span><span class="n">euler_maclaurin</span><span class="p">()</span>
<span class="go">(b**2/2 + b/2 - 1, 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">b**2/2 + b/2 - 1</span>
</pre></div>
</div>
<p>With a nonzero eps specified, the summation is ended
as soon as the remainder term is less than the epsilon.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.summations.Sum.eval_zeta_function">
<span class="sig-name descname"><span class="pre">eval_zeta_function</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limits</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L261-L274"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.Sum.eval_zeta_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Check whether the function matches with the zeta function.
If it matches, then return a <span class="math notranslate nohighlight">\(Piecewise\)</span> expression because
zeta function does not converge unless <span class="math notranslate nohighlight">\(s &gt; 1\)</span> and <span class="math notranslate nohighlight">\(q &gt; 0\)</span></p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.summations.Sum.is_absolutely_convergent">
<span class="sig-name descname"><span class="pre">is_absolutely_convergent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L646-L673"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.Sum.is_absolutely_convergent" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks for the absolute convergence of an infinite series.</p>
<p>Same as checking convergence of absolute value of sequence_term of
an infinite series.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">((</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="n">n</span><span class="p">,</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_absolutely_convergent</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">((</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="n">n</span><span class="o">/</span><span class="n">n</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_absolutely_convergent</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.summations.Sum.is_convergent" title="sympy.concrete.summations.Sum.is_convergent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Sum.is_convergent</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r83"><span class="brackets"><a class="fn-backref" href="#id4">R83</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Absolute_convergence">https://en.wikipedia.org/wiki/Absolute_convergence</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.summations.Sum.is_convergent">
<span class="sig-name descname"><span class="pre">is_convergent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L358-L644"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.Sum.is_convergent" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks for the convergence of a Sum.</p>
<p class="rubric">Explanation</p>
<p>We divide the study of convergence of infinite sums and products in
two parts.</p>
<p>First Part:
One part is the question whether all the terms are well defined, i.e.,
they are finite in a sum and also non-zero in a product. Zero
is the analogy of (minus) infinity in products as
<span class="math notranslate nohighlight">\(e^{-\infty} = 0\)</span>.</p>
<p>Second Part:
The second part is the question of convergence after infinities,
and zeros in products, have been omitted assuming that their number
is finite. This means that we only consider the tail of the sum or
product, starting from some point after which all terms are well
defined.</p>
<p>For example, in a sum of the form:</p>
<div class="math notranslate nohighlight">
\[\sum_{1 \leq i &lt; \infty} \frac{1}{n^2 + an + b}\]</div>
<p>where a and b are numbers. The routine will return true, even if there
are infinities in the term sequence (at most two). An analogous
product would be:</p>
<div class="math notranslate nohighlight">
\[\prod_{1 \leq i &lt; \infty} e^{\frac{1}{n^2 + an + b}}\]</div>
<p>This is how convergence is interpreted. It is concerned with what
happens at the limit. Finding the bad terms is another independent
matter.</p>
<p>Note: It is responsibility of user to see that the sum or product
is well defined.</p>
<p>There are various tests employed to check the convergence like
divergence test, root test, integral test, alternating series test,
comparison tests, Dirichlet tests. It returns true if Sum is convergent
and false if divergent and NotImplementedError if it can not be checked.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">factorial</span><span class="p">,</span> <span class="n">S</span><span class="p">,</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">n</span><span class="o">/</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">n</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="o">**</span><span class="n">n</span><span class="p">,</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">n</span><span class="o">**</span><span class="p">(</span><span class="n">S</span><span class="p">(</span><span class="mi">6</span><span class="p">)</span><span class="o">/</span><span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.summations.Sum.is_absolutely_convergent" title="sympy.concrete.summations.Sum.is_absolutely_convergent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Sum.is_absolutely_convergent</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product.is_convergent" title="sympy.concrete.products.Product.is_convergent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.Product.is_convergent</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r84"><span class="brackets"><a class="fn-backref" href="#id5">R84</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Convergence_tests">https://en.wikipedia.org/wiki/Convergence_tests</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.summations.Sum.reverse_order">
<span class="sig-name descname"><span class="pre">reverse_order</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">indices</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L780-L857"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.Sum.reverse_order" title="Permalink to this definition">¶</a></dt>
<dd><p>Reverse the order of a limit in a Sum.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">reverse_order(self,</span> <span class="pre">*indices)</span></code> reverses some limits in the expression
<code class="docutils literal notranslate"><span class="pre">self</span></code> which can be either a <code class="docutils literal notranslate"><span class="pre">Sum</span></code> or a <code class="docutils literal notranslate"><span class="pre">Product</span></code>. The selectors in
the argument <code class="docutils literal notranslate"><span class="pre">indices</span></code> specify some indices whose limits get reversed.
These selectors are either variable names or numerical indices counted
starting from the inner-most limit tuple.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Sum(-x, (x, 4, -1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="go">Sum(x*y, (x, 6, 0), (y, 7, -1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">Sum(-x, (x, b + 1, a - 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">Sum(-x, (x, b + 1, a - 1))</span>
</pre></div>
</div>
<p>While one should prefer variable names when specifying which limits
to reverse, the index counting notation comes in handy in case there
are several symbols with the same name.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span>
<span class="go">Sum(x**2, (x, a, b), (x, c, d))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span>
<span class="go">Sum(-x**2, (x, b + 1, a - 1), (x, c, d))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">=</span> <span class="n">S0</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span>
<span class="go">Sum(x**2, (x, b + 1, a - 1), (x, d + 1, c - 1))</span>
</pre></div>
</div>
<p>Of course we can mix both notations:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">Sum(x*y, (x, b + 1, a - 1), (y, 6, 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">Sum(x*y, (x, b + 1, a - 1), (y, 6, 1))</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder_limit</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r85"><span class="brackets"><a class="fn-backref" href="#id6">R85</a></span></dt>
<dd><p>Michael Karr, “Summation in Finite Terms”, Journal of the ACM,
Volume 28 Issue 2, April 1981, Pages 305-350
<a class="reference external" href="http://dl.acm.org/citation.cfm?doid=322248.322255">http://dl.acm.org/citation.cfm?doid=322248.322255</a></p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.concrete.products.Product">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.concrete.products.</span></span><span class="sig-name descname"><span class="pre">Product</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/products.py#L12-L565"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.products.Product" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents unevaluated products.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">Product</span></code> represents a finite or infinite product, with the first
argument being the general form of terms in the series, and the second
argument being <code class="docutils literal notranslate"><span class="pre">(dummy_variable,</span> <span class="pre">start,</span> <span class="pre">end)</span></code>, with <code class="docutils literal notranslate"><span class="pre">dummy_variable</span></code>
taking all integer values from <code class="docutils literal notranslate"><span class="pre">start</span></code> through <code class="docutils literal notranslate"><span class="pre">end</span></code>. In accordance
with long-standing mathematical convention, the end term is included in
the product.</p>
<p class="rubric">Finite Products</p>
<p>For finite products (and products with symbolic limits assumed to be finite)
we follow the analogue of the summation convention described by Karr [1],
especially definition 3 of section 1.4. The product:</p>
<div class="math notranslate nohighlight">
\[\prod_{m \leq i &lt; n} f(i)\]</div>
<p>has <em>the obvious meaning</em> for <span class="math notranslate nohighlight">\(m &lt; n\)</span>, namely:</p>
<div class="math notranslate nohighlight">
\[\prod_{m \leq i &lt; n} f(i) = f(m) f(m+1) \cdot \ldots \cdot f(n-2) f(n-1)\]</div>
<p>with the upper limit value <span class="math notranslate nohighlight">\(f(n)\)</span> excluded. The product over an empty set is
one if and only if <span class="math notranslate nohighlight">\(m = n\)</span>:</p>
<div class="math notranslate nohighlight">
\[\prod_{m \leq i &lt; n} f(i) = 1  \quad \mathrm{for} \quad  m = n\]</div>
<p>Finally, for all other products over empty sets we assume the following
definition:</p>
<div class="math notranslate nohighlight">
\[\prod_{m \leq i &lt; n} f(i) = \frac{1}{\prod_{n \leq i &lt; m} f(i)}  \quad \mathrm{for} \quad  m &gt; n\]</div>
<p>It is important to note that above we define all products with the upper
limit being exclusive. This is in contrast to the usual mathematical notation,
but does not affect the product convention. Indeed we have:</p>
<div class="math notranslate nohighlight">
\[\prod_{m \leq i &lt; n} f(i) = \prod_{i = m}^{n - 1} f(i)\]</div>
<p>where the difference in notation is intentional to emphasize the meaning,
with limits typeset on the top being inclusive.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Product</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">Product(k, (k, 1, m))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">factorial(m)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">k</span><span class="o">**</span><span class="mi">2</span><span class="p">,(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">Product(k**2, (k, 1, m))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">k</span><span class="o">**</span><span class="mi">2</span><span class="p">,(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">factorial(m)**2</span>
</pre></div>
</div>
<p>Wallis’ product for pi:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">W</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W</span>
<span class="go">Product(4*i**2/((2*i - 1)*(2*i + 1)), (i, 1, oo))</span>
</pre></div>
</div>
<p>Direct computation currently fails:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">W</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">Product(4*i**2/((2*i - 1)*(2*i + 1)), (i, 1, oo))</span>
</pre></div>
</div>
<p>But we can approach the infinite product by a limit of finite products:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">limit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W2</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W2</span>
<span class="go">Product(4*i**2/((2*i - 1)*(2*i + 1)), (i, 1, n))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W2e</span> <span class="o">=</span> <span class="n">W2</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">W2e</span>
<span class="go">4**n*factorial(n)**2/(2**(2*n)*RisingFactorial(1/2, n)*RisingFactorial(3/2, n))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">W2e</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">pi/2</span>
</pre></div>
</div>
<p>By the same formula we can compute sin(pi/2):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">combsimp</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">gamma</span><span class="p">,</span> <span class="n">simplify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">pi</span> <span class="o">*</span> <span class="n">x</span> <span class="o">*</span> <span class="n">Product</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="n">k</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">pi**2*Product(1 - pi**2/(4*k**2), (k, 1, n))/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pe</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pe</span>
<span class="go">pi**2*RisingFactorial(1 - pi/2, n)*RisingFactorial(1 + pi/2, n)/(2*factorial(n)**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">Pe</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span><span class="o">.</span><span class="n">gammasimp</span><span class="p">()</span>
<span class="go">sin(pi**2/2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pe</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span>
<span class="go">(-1)**n*pi**2*gamma(pi/2)*gamma(n + 1 + pi/2)/(2*gamma(1 + pi/2)*gamma(-n + pi/2)*gamma(n + 1)**2)</span>
</pre></div>
</div>
<p>Products with the lower limit being larger than the upper one:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">120</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">120</span>
</pre></div>
</div>
<p>The empty product:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">1</span>
</pre></div>
</div>
<p>An example showing that the symbolic result of a product is still
valid for seemingly nonsensical values of the limits. Then the Karr
convention allows us to give a perfectly valid interpretation to
those products by interchanging the limits according to the above rules:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">2**(n - 9)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">1/16</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">1/16</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span><span class="o">/</span><span class="n">Product</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">9</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">1/16</span>
</pre></div>
</div>
<p>An explicit example of the Karr summation convention applied to products:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span>
<span class="go">x**(-a + b + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P2</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">b</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">a</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P2</span>
<span class="go">x**(a - b - 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">P1</span> <span class="o">*</span> <span class="n">P2</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<p>And another one:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span>
<span class="go">RisingFactorial(b, a - b + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P2</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">b</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P2</span>
<span class="go">RisingFactorial(a + 1, -a + b - 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P1</span> <span class="o">*</span> <span class="n">P2</span>
<span class="go">RisingFactorial(b, a - b + 1)*RisingFactorial(a + 1, -a + b - 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">combsimp</span><span class="p">(</span><span class="n">P1</span> <span class="o">*</span> <span class="n">P2</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.summations.Sum" title="sympy.concrete.summations.Sum"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Sum</span></code></a>, <a class="reference internal" href="#sympy.concrete.summations.summation" title="sympy.concrete.summations.summation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">summation</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.product" title="sympy.concrete.products.product"><code class="xref py py-obj docutils literal notranslate"><span class="pre">product</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r86"><span class="brackets"><a class="fn-backref" href="#id7">R86</a></span></dt>
<dd><p>Michael Karr, “Summation in Finite Terms”, Journal of the ACM,
Volume 28 Issue 2, April 1981, Pages 305-350
<a class="reference external" href="http://dl.acm.org/citation.cfm?doid=322248.322255">http://dl.acm.org/citation.cfm?doid=322248.322255</a></p>
</dd>
<dt class="label" id="r87"><span class="brackets"><a class="fn-backref" href="#id8">R87</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Multiplication#Capital_Pi_notation">https://en.wikipedia.org/wiki/Multiplication#Capital_Pi_notation</a></p>
</dd>
<dt class="label" id="r88"><span class="brackets"><a class="fn-backref" href="#id9">R88</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Empty_product">https://en.wikipedia.org/wiki/Empty_product</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.products.Product.is_convergent">
<span class="sig-name descname"><span class="pre">is_convergent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/products.py#L419-L479"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.products.Product.is_convergent" title="Permalink to this definition">¶</a></dt>
<dd><p>See docs of <a class="reference internal" href="#sympy.concrete.summations.Sum.is_convergent" title="sympy.concrete.summations.Sum.is_convergent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Sum.is_convergent()</span></code></a> for explanation of convergence
in SymPy.</p>
<p class="rubric">Explanation</p>
<p>The infinite product:</p>
<div class="math notranslate nohighlight">
\[\prod_{1 \leq i &lt; \infty} f(i)\]</div>
<p>is defined by the sequence of partial products:</p>
<div class="math notranslate nohighlight">
\[\prod_{i=1}^{n} f(i) = f(1) f(2) \cdots f(n)\]</div>
<p>as n increases without bound. The product converges to a non-zero
value if and only if the sum:</p>
<div class="math notranslate nohighlight">
\[\sum_{1 \leq i &lt; \infty} \log{f(n)}\]</div>
<p>converges.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Product</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">n</span><span class="o">/</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">n</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">pi</span><span class="o">/</span><span class="n">n</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">n</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span><span class="o">.</span><span class="n">is_convergent</span><span class="p">()</span>
<span class="go">False</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r89"><span class="brackets"><a class="fn-backref" href="#id10">R89</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Infinite_product">https://en.wikipedia.org/wiki/Infinite_product</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.products.Product.reverse_order">
<span class="sig-name descname"><span class="pre">reverse_order</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">indices</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/products.py#L481-L565"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.products.Product.reverse_order" title="Permalink to this definition">¶</a></dt>
<dd><p>Reverse the order of a limit in a Product.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">reverse_order(expr,</span> <span class="pre">*indices)</span></code> reverses some limits in the expression
<code class="docutils literal notranslate"><span class="pre">expr</span></code> which can be either a <code class="docutils literal notranslate"><span class="pre">Sum</span></code> or a <code class="docutils literal notranslate"><span class="pre">Product</span></code>. The selectors in
the argument <code class="docutils literal notranslate"><span class="pre">indices</span></code> specify some indices whose limits get reversed.
These selectors are either variable names or numerical indices counted
starting from the inner-most limit tuple.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">gamma</span><span class="p">,</span> <span class="n">Product</span><span class="p">,</span> <span class="n">simplify</span><span class="p">,</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pr</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pr</span>
<span class="go">Product(1/x, (x, b + 1, a - 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pr</span> <span class="o">=</span> <span class="n">Pr</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Pr</span>
<span class="go">1/RisingFactorial(b + 1, a - b - 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">Pr</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">gamma</span><span class="p">))</span>
<span class="go">Piecewise((gamma(b + 1)/gamma(a), b &gt; -1), ((-1)**(-a + b + 1)*gamma(1 - a)/gamma(-b), True))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">RisingFactorial(a, -a + b + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">P</span><span class="o">.</span><span class="n">rewrite</span><span class="p">(</span><span class="n">gamma</span><span class="p">))</span>
<span class="go">Piecewise((gamma(b + 1)/gamma(a), a &gt; 0), ((-1)**(-a + b + 1)*gamma(1 - a)/gamma(-b), True))</span>
</pre></div>
</div>
<p>While one should prefer variable names when specifying which limits
to reverse, the index counting notation comes in handy in case there
are several symbols with the same name.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span>
<span class="go">Sum(x*y, (x, a, b), (y, c, d))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S0</span>
<span class="go">Sum(-x*y, (x, b + 1, a - 1), (y, c, d))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span> <span class="o">=</span> <span class="n">S0</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S1</span>
<span class="go">Sum(x*y, (x, b + 1, a - 1), (y, d + 1, c - 1))</span>
</pre></div>
</div>
<p>Of course we can mix both notations:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">Sum(x*y, (x, b + 1, a - 1), (y, 6, 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span><span class="o">.</span><span class="n">reverse_order</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">Sum(x*y, (x, b + 1, a - 1), (y, 6, 1))</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder_limit</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r90"><span class="brackets"><a class="fn-backref" href="#id11">R90</a></span></dt>
<dd><p>Michael Karr, “Summation in Finite Terms”, Journal of the ACM,
Volume 28 Issue 2, April 1981, Pages 305-350
<a class="reference external" href="http://dl.acm.org/citation.cfm?doid=322248.322255">http://dl.acm.org/citation.cfm?doid=322248.322255</a></p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.concrete.expr_with_intlimits.ExprWithIntLimits">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.concrete.expr_with_intlimits.</span></span><span class="sig-name descname"><span class="pre">ExprWithIntLimits</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/expr_with_intlimits.py#L13-L352"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits" title="Permalink to this definition">¶</a></dt>
<dd><p>Superclass for Product and Sum.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="integrals/integrals.html#sympy.concrete.expr_with_limits.ExprWithLimits" title="sympy.concrete.expr_with_limits.ExprWithLimits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_limits.ExprWithLimits</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product" title="sympy.concrete.products.Product"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.Product</span></code></a>, <a class="reference internal" href="#sympy.concrete.summations.Sum" title="sympy.concrete.summations.Sum"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.summations.Sum</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.change_index">
<span class="sig-name descname"><span class="pre">change_index</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">var</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">trafo</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">newvar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/expr_with_intlimits.py#L24-L140"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.change_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Change index of a Sum or Product.</p>
<p>Perform a linear transformation <span class="math notranslate nohighlight">\(x \mapsto a x + b\)</span> on the index variable
<span class="math notranslate nohighlight">\(x\)</span>. For <span class="math notranslate nohighlight">\(a\)</span> the only values allowed are <span class="math notranslate nohighlight">\(\pm 1\)</span>. A new variable to be used
after the change of index can also be specified.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">change_index(expr,</span> <span class="pre">var,</span> <span class="pre">trafo,</span> <span class="pre">newvar=None)</span></code> where <code class="docutils literal notranslate"><span class="pre">var</span></code> specifies the
index variable <span class="math notranslate nohighlight">\(x\)</span> to transform. The transformation <code class="docutils literal notranslate"><span class="pre">trafo</span></code> must be linear
and given in terms of <code class="docutils literal notranslate"><span class="pre">var</span></code>. If the optional argument <code class="docutils literal notranslate"><span class="pre">newvar</span></code> is
provided then <code class="docutils literal notranslate"><span class="pre">var</span></code> gets replaced by <code class="docutils literal notranslate"><span class="pre">newvar</span></code> in the final expression.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Product</span><span class="p">,</span> <span class="n">simplify</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">S</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">S</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-a**2/2 + a/2 + b**2/2 + b/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span>
<span class="go">Sum(y - 1, (y, a + 1, b + 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-a**2/2 + a/2 + b**2/2 + b/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span>
<span class="go">Sum(-y, (y, -b, -a))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-a**2/2 + a/2 + b**2/2 + b/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="o">+</span><span class="n">u</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span>
<span class="go">Sum(-u + x, (x, a + u, b + u))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-a**2/2 - a*u + a/2 + b**2/2 + b*u + b/2 - u*(-a + b + 1) + u</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">())</span>
<span class="go">-a**2/2 + a/2 + b**2/2 + b/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="n">x</span> <span class="o">-</span> <span class="n">u</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span>
<span class="go">Sum(-u - y, (y, -b - u, -a - u))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-a**2/2 - a*u + a/2 + b**2/2 + b*u + b/2 - u*(-a + b + 1) + u</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">())</span>
<span class="go">-a**2/2 + a/2 + b**2/2 + b/2</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">i</span><span class="o">*</span><span class="n">j</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span>
<span class="go">Product(i*j**2, (i, a, b), (j, c, d))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P2</span> <span class="o">=</span> <span class="n">P</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span><span class="o">+</span><span class="mi">3</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P2</span>
<span class="go">Product(j**2*(k - 3), (k, a + 3, b + 3), (j, c, d))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P3</span> <span class="o">=</span> <span class="n">P2</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="o">-</span><span class="n">j</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P3</span>
<span class="go">Product(l**2*(k - 3), (k, a + 3, b + 3), (l, -d, -c))</span>
</pre></div>
</div>
<p>When dealing with symbols only, we can make a
general linear transformation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">change_index</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">u</span><span class="o">*</span><span class="n">x</span><span class="o">+</span><span class="n">v</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span>
<span class="go">Sum((-v + y)/u, (y, b*u + v, a*u + v))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span>
<span class="go">-v*(a*u - b*u + 1)/u + (a**2*u**2/2 + a*u*v + a*u/2 - b**2*u**2/2 - b*u*v + b*u/2 + v)/u</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">simplify</span><span class="p">(</span><span class="n">Sn</span><span class="o">.</span><span class="n">doit</span><span class="p">())</span>
<span class="go">a**2*u/2 + a/2 - b**2*u/2 + b/2</span>
</pre></div>
</div>
<p>However, the last result can be inconsistent with usual
summation where the index increment is always 1. This is
obvious as we get back the original value only for <code class="docutils literal notranslate"><span class="pre">u</span></code>
equal +1 or -1.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder_limit</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder</span></code></a>, <a class="reference internal" href="#sympy.concrete.summations.Sum.reverse_order" title="sympy.concrete.summations.Sum.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.summations.Sum.reverse_order</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product.reverse_order" title="sympy.concrete.products.Product.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.Product.reverse_order</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.has_empty_sequence">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">has_empty_sequence</span></span><a class="headerlink" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.has_empty_sequence" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if the Sum or Product is computed for an empty sequence.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Product</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;m&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">M</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">M</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">M</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">M</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">M</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">M</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">N</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">negative</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">M</span><span class="p">))</span><span class="o">.</span><span class="n">has_empty_sequence</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="integrals/integrals.html#sympy.concrete.expr_with_limits.ExprWithLimits.has_reversed_limits" title="sympy.concrete.expr_with_limits.ExprWithLimits.has_reversed_limits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">has_reversed_limits</span></code></a>, <a class="reference internal" href="integrals/integrals.html#sympy.concrete.expr_with_limits.ExprWithLimits.has_finite_limits" title="sympy.concrete.expr_with_limits.ExprWithLimits.has_finite_limits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">has_finite_limits</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index">
<span class="sig-name descname"><span class="pre">index</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/expr_with_intlimits.py#L143-L179"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the index of a dummy variable in the list of limits.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">index(expr,</span> <span class="pre">x)</span></code>  returns the index of the dummy variable <code class="docutils literal notranslate"><span class="pre">x</span></code> in the
limits of <code class="docutils literal notranslate"><span class="pre">expr</span></code>. Note that we start counting with 0 at the inner-most
limits tuple.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Product</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder_limit</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder</span></code></a>, <a class="reference internal" href="#sympy.concrete.summations.Sum.reverse_order" title="sympy.concrete.summations.Sum.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.summations.Sum.reverse_order</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product.reverse_order" title="sympy.concrete.products.Product.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.Product.reverse_order</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder">
<span class="sig-name descname"><span class="pre">reorder</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/expr_with_intlimits.py#L181-L243"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder" title="Permalink to this definition">¶</a></dt>
<dd><p>Reorder limits in a expression containing a Sum or a Product.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">expr.reorder(*arg)</span></code> reorders the limits in the expression <code class="docutils literal notranslate"><span class="pre">expr</span></code>
according to the list of tuples given by <code class="docutils literal notranslate"><span class="pre">arg</span></code>. These tuples can
contain numerical indices or index variable names or involve both.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Product</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">reorder</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="go">Sum(x*y, (y, c, d), (x, a, b))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span><span class="o">.</span><span class="n">reorder</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">))</span>
<span class="go">Sum(x*y*z, (z, e, f), (y, c, d), (x, a, b))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="o">.</span><span class="n">reorder</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">))</span>
<span class="go">Product(x*y*z, (z, e, f), (y, c, d), (x, a, b))</span>
</pre></div>
</div>
<p>We can also select the index variables by counting them, starting
with the inner-most one:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">reorder</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="go">Sum(x**2, (x, c, d), (x, a, b))</span>
</pre></div>
</div>
<p>And of course we can mix both schemes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">reorder</span><span class="p">((</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="go">Sum(x*y, (y, c, d), (x, a, b))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">reorder</span><span class="p">((</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">Sum(x*y, (y, c, d), (x, a, b))</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder_limit</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">index</span></code></a>, <a class="reference internal" href="#sympy.concrete.summations.Sum.reverse_order" title="sympy.concrete.summations.Sum.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.summations.Sum.reverse_order</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product.reverse_order" title="sympy.concrete.products.Product.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.Product.reverse_order</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit">
<span class="sig-name descname"><span class="pre">reorder_limit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/expr_with_intlimits.py#L246-L298"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder_limit" title="Permalink to this definition">¶</a></dt>
<dd><p>Interchange two limit tuples of a Sum or Product expression.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">expr.reorder_limit(x,</span> <span class="pre">y)</span></code> interchanges two limit tuples. The
arguments <code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">y</span></code> are integers corresponding to the index
variables of the two limits which are to be interchanged. The
expression <code class="docutils literal notranslate"><span class="pre">expr</span></code> has to be either a Sum or a Product.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Product</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span><span class="o">.</span><span class="n">reorder_limit</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Sum(x*y*z, (z, e, f), (y, c, d), (x, a, b))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Sum</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span><span class="o">.</span><span class="n">reorder_limit</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">Sum(x**2, (x, c, d), (x, a, b))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Product</span><span class="p">(</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">z</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">),</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span><span class="o">.</span><span class="n">reorder_limit</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Product(x*y*z, (z, e, f), (y, c, d), (x, a, b))</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">index</span></code></a>, <a class="reference internal" href="#sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder" title="sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">reorder</span></code></a>, <a class="reference internal" href="#sympy.concrete.summations.Sum.reverse_order" title="sympy.concrete.summations.Sum.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.summations.Sum.reverse_order</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product.reverse_order" title="sympy.concrete.products.Product.reverse_order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.Product.reverse_order</span></code></a></p>
</div>
</dd></dl>

</dd></dl>

</section>
<section id="concrete-functions-reference">
<h2>Concrete Functions Reference<a class="headerlink" href="#concrete-functions-reference" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.concrete.summations.summation">
<span class="sig-prename descclassname"><span class="pre">sympy.concrete.summations.</span></span><span class="sig-name descname"><span class="pre">summation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">symbols</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/summations.py#L860-L910"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.summations.summation" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the summation of f with respect to symbols.</p>
<p class="rubric">Explanation</p>
<p>The notation for symbols is similar to the notation used in Integral.
summation(f, (i, a, b)) computes the sum of f with respect to i from a to b,
i.e.,</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>                            b
                          ____
                          \   `
summation(f, (i, a, b)) =  )    f
                          /___,
                          i = a
</pre></div>
</div>
<p>If it cannot compute the sum, it returns an unevaluated Sum object.
Repeated sums can be computed by introducing additional symbols tuples:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">..</span> <span class="n">rubric</span><span class="p">::</span> <span class="n">Examples</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">summation</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">log</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;i n m&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">summation</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="go">n**2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">summation</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="mi">2</span><span class="o">**</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">summation</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">log</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">**</span><span class="n">n</span><span class="p">,</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">Sum(log(n)**(-n), (n, 2, oo))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">summation</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">m**3/6 + m**2/2 + m/3</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">factorial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">summation</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="n">n</span><span class="o">/</span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">exp(x)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.concrete.summations.Sum" title="sympy.concrete.summations.Sum"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Sum</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.Product" title="sympy.concrete.products.Product"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Product</span></code></a>, <a class="reference internal" href="#sympy.concrete.products.product" title="sympy.concrete.products.product"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.concrete.products.product</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.concrete.products.product">
<span class="sig-prename descclassname"><span class="pre">sympy.concrete.products.</span></span><span class="sig-name descname"><span class="pre">product</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/products.py#L568-L610"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.products.product" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the product.</p>
<p class="rubric">Explanation</p>
<p>The notation for symbols is similar to the notation used in Sum or
Integral. product(f, (i, a, b)) computes the product of f with
respect to i from a to b, i.e.,</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>                             <span class="n">b</span>
                           <span class="n">_____</span>
<span class="n">product</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">n</span><span class="p">),</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span> <span class="o">=</span> <span class="o">|</span>   <span class="o">|</span> <span class="n">f</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
                           <span class="o">|</span>   <span class="o">|</span>
                           <span class="n">i</span> <span class="o">=</span> <span class="n">a</span>
</pre></div>
</div>
<p>If it cannot compute the product, it returns an unevaluated Product object.
Repeated products can be computed by introducing additional symbols tuples:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">..</span> <span class="n">rubric</span><span class="p">::</span> <span class="n">Examples</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">product</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">k</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;i n m k&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">product</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>
<span class="go">factorial(k)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">product</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>
<span class="go">m**k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">product</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="p">),</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="go">Product(factorial(k), (k, 1, n))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.concrete.gosper.gosper_normal">
<span class="sig-prename descclassname"><span class="pre">sympy.concrete.gosper.</span></span><span class="sig-name descname"><span class="pre">gosper_normal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">g</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">polys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/gosper.py#L10-L82"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.gosper.gosper_normal" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the Gosper’s normal form of <code class="docutils literal notranslate"><span class="pre">f</span></code> and <code class="docutils literal notranslate"><span class="pre">g</span></code>.</p>
<p class="rubric">Explanation</p>
<p>Given relatively prime univariate polynomials <code class="docutils literal notranslate"><span class="pre">f</span></code> and <code class="docutils literal notranslate"><span class="pre">g</span></code>,
rewrite their quotient to a normal form defined as follows:</p>
<div class="math notranslate nohighlight">
\[\frac{f(n)}{g(n)} = Z \cdot \frac{A(n) C(n+1)}{B(n) C(n)}\]</div>
<p>where <code class="docutils literal notranslate"><span class="pre">Z</span></code> is an arbitrary constant and <code class="docutils literal notranslate"><span class="pre">A</span></code>, <code class="docutils literal notranslate"><span class="pre">B</span></code>, <code class="docutils literal notranslate"><span class="pre">C</span></code> are
monic polynomials in <code class="docutils literal notranslate"><span class="pre">n</span></code> with the following properties:</p>
<ol class="arabic simple">
<li><p><span class="math notranslate nohighlight">\(\gcd(A(n), B(n+h)) = 1 \forall h \in \mathbb{N}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gcd(B(n), C(n+1)) = 1\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gcd(A(n), C(n)) = 1\)</span></p></li>
</ol>
<p>This normal form, or rational factorization in other words, is a
crucial step in Gosper’s algorithm and in solving of difference
equations. It can be also used to decide if two hypergeometric
terms are similar or not.</p>
<p>This procedure will return a tuple containing elements of this
factorization in the form <code class="docutils literal notranslate"><span class="pre">(Z*A,</span> <span class="pre">B,</span> <span class="pre">C)</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.concrete.gosper</span> <span class="kn">import</span> <span class="n">gosper_normal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">n</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gosper_normal</span><span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="n">n</span><span class="o">+</span><span class="mi">5</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span><span class="o">+</span><span class="mi">3</span><span class="p">),</span> <span class="n">n</span><span class="p">,</span> <span class="n">polys</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(1/4, n + 3/2, n + 1/4)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.concrete.gosper.gosper_term">
<span class="sig-prename descclassname"><span class="pre">sympy.concrete.gosper.</span></span><span class="sig-name descname"><span class="pre">gosper_term</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/gosper.py#L85-L161"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.gosper.gosper_term" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute Gosper’s hypergeometric term for <code class="docutils literal notranslate"><span class="pre">f</span></code>.</p>
<p class="rubric">Explanation</p>
<p>Suppose <code class="docutils literal notranslate"><span class="pre">f</span></code> is a hypergeometric term such that:</p>
<div class="math notranslate nohighlight">
\[s_n = \sum_{k=0}^{n-1} f_k\]</div>
<p>and <span class="math notranslate nohighlight">\(f_k\)</span> doesn’t depend on <span class="math notranslate nohighlight">\(n\)</span>. Returns a hypergeometric
term <span class="math notranslate nohighlight">\(g_n\)</span> such that <span class="math notranslate nohighlight">\(g_{n+1} - g_n = f_n\)</span>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.concrete.gosper</span> <span class="kn">import</span> <span class="n">gosper_term</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">factorial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">n</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">gosper_term</span><span class="p">((</span><span class="mi">4</span><span class="o">*</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">factorial</span><span class="p">(</span><span class="n">n</span><span class="p">)</span><span class="o">/</span><span class="n">factorial</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="n">n</span><span class="p">)</span>
<span class="go">(-n - 1/2)/(n + 1/4)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.concrete.gosper.gosper_sum">
<span class="sig-prename descclassname"><span class="pre">sympy.concrete.gosper.</span></span><span class="sig-name descname"><span class="pre">gosper_sum</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/concrete/gosper.py#L164-L227"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.concrete.gosper.gosper_sum" title="Permalink to this definition">¶</a></dt>
<dd><p>Gosper’s hypergeometric summation algorithm.</p>
<p class="rubric">Explanation</p>
<p>Given a hypergeometric term <code class="docutils literal notranslate"><span class="pre">f</span></code> such that:</p>
<div class="math notranslate nohighlight">
\[s_n = \sum_{k=0}^{n-1} f_k\]</div>
<p>and <span class="math notranslate nohighlight">\(f(n)\)</span> doesn’t depend on <span class="math notranslate nohighlight">\(n\)</span>, returns <span class="math notranslate nohighlight">\(g_{n} - g(0)\)</span> where
<span class="math notranslate nohighlight">\(g_{n+1} - g_n = f_n\)</span>, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if <span class="math notranslate nohighlight">\(s_n\)</span> can not be expressed
in closed form as a sum of hypergeometric terms.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.concrete.gosper</span> <span class="kn">import</span> <span class="n">gosper_sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">factorial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">n</span><span class="p">,</span> <span class="n">k</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="p">(</span><span class="mi">4</span><span class="o">*</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">factorial</span><span class="p">(</span><span class="n">k</span><span class="p">)</span><span class="o">/</span><span class="n">factorial</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gosper_sum</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="go">(-factorial(n) + 2*factorial(2*n + 1))/factorial(2*n + 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="nb">sum</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">gosper_sum</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="go">(-60*factorial(n) + factorial(2*n + 1))/(60*factorial(2*n + 1))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="o">==</span> <span class="nb">sum</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r91"><span class="brackets"><a class="fn-backref" href="#id12">R91</a></span></dt>
<dd><p>Marko Petkovsek, Herbert S. Wilf, Doron Zeilberger, A = B,
AK Peters, Ltd., Wellesley, MA, USA, 1997, pp. 73–100</p>
</dd>
</dl>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Concrete</a><ul>
<li><a class="reference internal" href="#hypergeometric-terms">Hypergeometric terms</a></li>
<li><a class="reference internal" href="#concrete-class-reference">Concrete Class Reference</a></li>
<li><a class="reference internal" href="#concrete-functions-reference">Concrete Functions Reference</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="combinatorics/pc_groups.html"
                        title="previous chapter">Polycyclic Groups</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="core.html"
                        title="next chapter">Core</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/modules/concrete.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="core.html" title="Core"
             >next</a> |</li>
        <li class="right" >
          <a href="combinatorics/pc_groups.html" title="Polycyclic Groups"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Concrete</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/concrete.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:24:09 GMT -->
</html>